!function (t, e) {
    var n, s, a = e.body, o = e.querySelector.bind(e), c = e.querySelectorAll.bind(e), l = o("html"), r = o("#gotop"),
        d = o("#menu"), h = o("#header"), f = o("#mask"), u = o("#menu-toggle"), v = o("#menu-off"), m = o("#loading"),
        g = t.requestAnimationFrame, L = Array.prototype.forEach,
        p = "ontouchstart" in t && /Mobile|Android|iOS|iPhone|iPad|iPod|Windows Phone|KFAPWI/i.test(navigator.userAgent) ? "touchstart" : "click",
        w = /micromessenger/i.test(navigator.userAgent), y = function () {
        }, $ = function (t) {
            var e = t.offsetLeft, i = t.offsetTop;
            if (t.offsetParent) {
                var n = arguments.callee(t.offsetParent);
                e += n.x, i += n.y
            }
            return {x: e, y: i}
        }, x = function () {
            return e.documentElement.scrollTop || e.body.scrollTop
        }, E = {
            goTop: function (e) {
                var i = x(), n = arguments.length > 2 ? arguments[1] : Math.abs(i - e) / 12;
                i && i > e ? (t.scrollTo(0, Math.max(i - n, 0)), g(arguments.callee.bind(this, e, n))) : e && i < e ? (t.scrollTo(0, Math.min(i + n, e)), g(arguments.callee.bind(this, e, n))) : null
            },
            toggleGotop: function (e) {
                e > t.innerHeight / 2 ? r.classList.add("in") : r.classList.remove("in")
            },
            toggleMenu: function (e) {
                var i = o("#main");
                if (e) {
                    if (d.classList.remove("hide"), t.innerWidth < 1241) if (f.classList.add("in"), d.classList.add("show"), w) {
                        var n = x();
                        i.classList.add("lock"), i.scrollTop = n
                    } else l.classList.add("lock")
                } else if (d.classList.remove("show"), f.classList.remove("in"), w) {
                    n = i.scrollTop;
                    i.classList.remove("lock"), t.scrollTo(0, n)
                } else l.classList.remove("lock")
            },
            fixedHeader: function (t) {
                t > h.clientHeight ? h.classList.add("fixed") : h.classList.remove("fixed")
            },
            // toc: function () {
            //     var t = o("#post-toc");
            //     if (!t || !t.children.length) return {fixed: y, actived: y};
            //     var e = o(".post-card-title").clientHeight, n = h.clientHeight,
            //         s = o("#post-content").querySelectorAll("h1, h2, h3, h4, h5, h6");
            //     return t.querySelector('a[href="#' + s[0].id + '"]').parentNode.classList.add("active"), {
            //         fixed: function (i) {
            //             i >= e - n ? t.classList.add("fixed") : t.classList.remove("fixed")
            //         }, actived: function (e) {
            //             for (let i = 0, len = s.length; i < len; i++) {
            //                 if (e > $(s[i]).y - n - 5) t.querySelector("li.active").classList.remove("active"), t.querySelector('a[href="#' + s[i].id + '"]').parentNode.classList.add("active")
            //             }
            //             e < $(s[0]).y && (t.querySelector("li.active").classList.remove("active"), t.querySelector('a[href="#' + s[0].id + '"]').parentNode.classList.add("active"))
            //         }
            //     }
            // }(),
            hideOnMask: [],
            modal: function (t) {
                this.$modal = o(t), this.$off = this.$modal.querySelector(".close");
                var e = this;
                this.show = function () {
                    f.classList.add("in"), e.$modal.classList.add("ready"), setTimeout(function () {
                        e.$modal.classList.add("in")
                    }, 0)
                }, this.onHide = y, this.hide = function () {
                    e.onHide(), f.classList.remove("in"), e.$modal.classList.remove("in"), setTimeout(function () {
                        e.$modal.classList.remove("ready")
                    }, 300)
                }, this.toggle = function () {
                    return e.$modal.classList.contains("in") ? e.hide() : e.show()
                }, E.hideOnMask.push(this.hide), this.$off && this.$off.addEventListener(p, this.hide)
            },
            // share: function () {
            //     var t = o("#pageShare"), i = o("#shareFab"), n = new this.modal("#globalShare");
            //     o("#menuShare").addEventListener(p, n.toggle), i && (i.addEventListener(p, function () {
            //         t.classList.toggle("in")
            //     }, !1), e.addEventListener(p, function (e) {
            //         !i.contains(e.target) && t.classList.remove("in")
            //     }, !1));
            //     var s = new this.modal("#wxShare");
            //     s.onHide = n.hide, L.call(c(".wxFab"), function (t) {
            //         t.addEventListener(p, s.toggle)
            //     })
            // },
            search: function () {
                var t = o("#search-wrap");
                o("#search").addEventListener(p, function () {
                    t.classList.toggle("in")
                })
            },
            waterfall: function () {
                t.innerWidth < 760 || L.call(c(".waterfall"), function (t) {
                    var e = t.querySelectorAll(".waterfall-item"), i = [0, 0];
                    L.call(e, function (t) {
                        var e = i[0] <= i[1] ? 0 : 1;
                        t.style.cssText = "top:" + i[e] + "px;left:" + (e > 0 ? "50%" : 0), i[e] += t.offsetHeight
                    }), t.style.height = Math.max(i[0], i[1]) + "px", t.classList.add("in")
                })
            },
            tabBar: function (t) {
                t.parentNode.parentNode.classList.toggle("expand")
            },
            page: (n = c(".fade, .fade-scale"), s = !1, {
                loaded: function () {
                    L.call(n, function (t) {
                        t.classList.add("in")
                    }), s = !0
                }, unload: function () {
                    L.call(n, function (t) {
                        t.classList.remove("in")
                    }), s = !1
                }, visible: s
            }),
            lightbox: function () {
                L.call(c(".img-lightbox"), function (i) {
                    new function (i) {
                        var n, s, o, c, l;
                        this.$img = i.querySelector("img"), this.$overlay = i.querySelector("overlay"), this.margin = 40, this.title = this.$img.title || this.$img.alt || "", this.isZoom = !1, this.calcRect = function () {
                            c = a.clientWidth;
                            var t = (l = a.clientHeight) - 2 * this.margin, e = n, i = s,
                                r = (this.margin, e > c ? c / e : 1), d = i > t ? t / i : 1, h = Math.min(r, d);
                            return {
                                w: e *= h,
                                h: i *= h,
                                t: (l - i) / 2 - o.top,
                                l: (c - e) / 2 - o.left + this.$img.offsetLeft
                            }
                        }, this.setImgRect = function (t) {
                            this.$img.style.cssText = "width: " + t.w + "px; max-width: " + t.w + "px; height:" + t.h + "px; top: " + t.t + "px; left: " + t.l + "px"
                        }, this.setFrom = function () {
                            this.setImgRect({w: o.width, h: o.height, t: 0, l: (i.offsetWidth - o.width) / 2})
                        }, this.setTo = function () {
                            this.setImgRect(this.calcRect())
                        }, this.addTitle = function () {
                            this.title && (this.$caption = e.createElement("div"), this.$caption.innerHTML = this.title, this.$caption.className = "overlay-title", i.appendChild(this.$caption))
                        }, this.removeTitle = function () {
                            this.$caption && i.removeChild(this.$caption)
                        };
                        var r = this;
                        this.zoomIn = function () {
                            n = this.$img.naturalWidth || this.$img.width, s = this.$img.naturalHeight || this.$img.height, o = this.$img.getBoundingClientRect(), i.style.height = o.height + "px", i.classList.add("ready"), this.setFrom(), this.addTitle(), this.$img.classList.add("zoom-in"), setTimeout(function () {
                                i.classList.add("active"), r.setTo(), r.isZoom = !0
                            }, 0)
                        }, this.zoomOut = function () {
                            this.isZoom = !1, i.classList.remove("active"), this.$img.classList.add("zoom-in"), this.setFrom(), setTimeout(function () {
                                r.$img.classList.remove("zoom-in"), r.$img.style.cssText = "", r.removeTitle(), i.classList.remove("ready"), i.removeAttribute("style")
                            }, 300)
                        }, i.addEventListener("click", function (t) {
                            r.isZoom ? r.zoomOut() : "IMG" === t.target.tagName && r.zoomIn()
                        }), e.addEventListener("scroll", function () {
                            r.isZoom && r.zoomOut()
                        }), t.addEventListener("resize", function () {
                            r.isZoom && r.zoomOut()
                        })
                    }(i)
                })
            }(),
            loadScript: function (t) {
                t.forEach(function (t) {
                    var i = e.createElement("script");
                    i.src = t, i.async = !0, a.appendChild(i)
                })
            },
            dialog: function (t, e, i, n) {
                var s = new this.modal("#dialog");
                o(".mdui-dialog-title").innerText = t, o(".mdui-dialog-content").innerText = e, i && o("#btnOK").addEventListener("click", i), n && o("#btnCancel").addEventListener("click", function () {
                    n(), s.hide()
                })
            }
        };
    t.addEventListener("load", function () {
        m.classList.remove("active"), E.page.loaded(), t.lazyScripts && t.lazyScripts.length && E.loadScript(t.lazyScripts)
    }), t.addEventListener("DOMContentLoaded", function () {
        E.waterfall();
        var t = x();
        E.toc.fixed(t), E.toc.actived(t), E.page.loaded()
    });
    var T = !1, b = o('a[href^="mailto"]');
    b && b.addEventListener(p, function () {
        T = !0
    }), t.addEventListener("beforeunload", function () {
        T ? T = !1 : E.page.unload()
    }), t.addEventListener("pageshow", function () {
        !E.page.visible && E.page.loaded()
    }), t.addEventListener("resize", function () {
        t.BLOG.even = p = "ontouchstart" in t ? "touchstart" : "click", E.toggleMenu(), E.waterfall()
    }), r.addEventListener(p, function () {
        g(E.goTop.bind(E, 0))
    }, !1), u.addEventListener(p, function (t) {
        E.toggleMenu(!0), t.preventDefault()
    }, !1), v.addEventListener(p, function () {
        d.classList.add("hide")
    }, !1), f.addEventListener(p, function (t) {
        E.toggleMenu(), E.hideOnMask.forEach(function (t) {
            t()
        }), t.preventDefault()
    }, !1), e.addEventListener("scroll", function () {
        var t = x();
        E.toggleGotop(t), E.fixedHeader(t)
    }, !1), t.BLOG.REWARD, E.noop = y, E.even = p, E.$ = o, E.$$ = c, Object.keys(E).reduce(function (t, e) {
        return t[e] = E[e], t
    }, t.BLOG), t.Waves ? (t.Waves.init(), t.Waves.attach(".global-share li", ["waves-block"]), t.Waves.attach(".article-tag-list-link, #page-nav a, #page-nav span", ["waves-button"])) : console.error("Waves loading failed.")
}(window, document);
